﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Web_Oto.Bases;
using Web_Oto.Data;
using Web_Oto.Data.Dto;

namespace Web_Oto.Business
{
    public class CategoryBus : busObject
    {
        #region Constructor

        public CategoryBus() : base()
        {
            m_objDAL = new CategoryDal(base.connectionstring, base.connectiontype);
        }

        public CategoryBus(string connectionString) : base(connectionString)
        {
            m_objDAL = new CategoryDal(base.connectionstring, base.connectiontype);
        }

        public CategoryBus(string connectionString, string connectionType)
            : base(connectionString, connectionType)
        {
            m_objDAL = new CategoryDal(base.connectionstring, base.connectiontype);
        }

        private CategoryDal m_objDAL;

        #endregion

        #region methods

        public IList<Category> GetCategories()
        {
            return m_objDAL.GetCategories();
        }

        public Category GetCategoryById(int id)
        {
            return m_objDAL.GetCategoryById(id);
        }

        public List<CategoryDto> GetCategoryDtos(string name = "", int parentId = 0)
        {
            return m_objDAL.GetCategoryDtos(name, parentId);
        }

        public int Delete(int id)
        {
            return m_objDAL.Delete(id);
        }

        public int Update(Category category)
        {            
            if (category.ParentId == 0)
                category.ParentId = null;
            return m_objDAL.Update(category);
        }

        public List<Category> GetCategoryParents()
        {
            return m_objDAL.GetCategoryParents();
        }

        public int Insert(Category category)
        {
            if (category.ParentId == 0)
                category.ParentId = null;
            return m_objDAL.Insert(category);
        }

        public IList<Category> GetCategoryByParentId(int? parentId)
        {
            return m_objDAL.GetCategoryByParentId(parentId);
        }

        public List<Category> GetChildrenCategoryDtos()
        {
            return m_objDAL.GetChildrenCategoryDtos();
        }

        public IList<Category> GetSubCategories()
        {
            return m_objDAL.GetSubCategories();
        }

        #endregion
    }
}
